package database.util;

import model.didactic.Activity;
import model.didactic.ActivityType;
import model.didactic.InformationSource;
import model.sporteli.ActionInformation;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Author: Kostika Gorica
 * User:   kosta
 * Date:   1/1/13
 * Time:   11:21 PM
 */
public class ArrayListToXML {
    private static String XML_HEADER = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

    public static String toActivityTypesXML(ArrayList<ActivityType> types){
        StringBuffer buffer = new StringBuffer();
        buffer.append(XML_HEADER);
        buffer.append("<resource name=\"ActivityTypes\" >");
        if (types!=null && types.size()>0){
            for (ActivityType type : types){
                buffer.append("<activityType>");
                buffer.append("<id>"+type.getId()+"</id>");
                buffer.append("<name>"+type.getTypeName()+"</name>");
                buffer.append("<description>"+type.getDescription()+"</description>");
                buffer.append("</activityType>");
            }
        }
        buffer.append("</resource>");

        return buffer.toString();
    }

    public static String toActivitiesXML(ArrayList<Activity> activities){
        StringBuffer buffer = new StringBuffer();
        buffer.append(XML_HEADER);
        buffer.append("<resource name=\"Activities\" >");
        if (activities!=null && activities.size()>0){
            for (Activity activity : activities){
                buffer.append("<activity>");
                buffer.append("<id>"+activity.getId()+"</id>");
                buffer.append("<type>"+activity.getActivityType()+"</type>");
                buffer.append("<name>"+activity.getActivityName()+"</name>");
                buffer.append("<description>"+activity.getDescription()+"</description>");
                buffer.append("</activity>");
            }
        }
        buffer.append("</resource>");

        return buffer.toString();
    }


    public static String toInformationSourcesXML(ArrayList<InformationSource> sources){
        StringBuffer buffer = new StringBuffer();
        buffer.append(XML_HEADER);
        buffer.append("<resource name=\"InformationSource\" >");
        if (sources != null && sources.size()>0){
            for (InformationSource source : sources){
                buffer.append("<source>");
                buffer.append("<id>"+source.getId()+"</id>");
                buffer.append("<name>"+source.getSourceName()+"</name>");
                buffer.append("<description>"+source.getDescription()+"</description>");
                buffer.append("<parent>"+source.getParentId()+"</parent>");
                buffer.append("</source>");
            }
            buffer.append("</resource>");
        }
        return buffer.toString();
    }


    public static String toActionInformationXML(ArrayList<ActionInformation> actions){
        StringBuffer buffer = new StringBuffer();
        buffer.append(XML_HEADER);
        buffer.append("<resource name=\"ActionInformation\" >");
        if (actions != null && actions.size()>0){
            for (ActionInformation ac : actions){
                buffer.append("<action>");
                buffer.append("<id>"+ac.getId()+"</id>");
                buffer.append("<person id=\""+ac.getPersonId()+"\">"+"kot"+  "</person>");       //TODO person name
                buffer.append("<dateAction>"+ac.getActionDate().toString()+"</dateAction>");    //TODO formatDate
                buffer.append("<interesed>"+ac.getDataInteresimit()+"</interesed>");
                buffer.append("<fusha id=\""+ac.getFushaInteresimitID()+"\">"+"kot"+ "</fusha>");   //TODO fusha name
                buffer.append("<nenfusha id=\""+ac.getNenFushaInteresimitID()+"\">"+"</nenfusha>");
                buffer.append("<sourceInfo id=\""+ac.getInformationSourceID()+"\">"+"</sourceInfo>");
                buffer.append("<subSourceInfo id=\""+ac.getInformationSubSourceID()+"\">"+"</subSourceInfo>");
                buffer.append("<noDocs>"+ac.getNoDocuments()+"</noDocs>");
                buffer.append("<note>"+ac.getNotes()+"</note>");
                buffer.append("</action>");
            }
            buffer.append("</resource>");
        }
        return buffer.toString();
    }
}
